<template>
  <div class="cartoon-form-container">
<!--    <el-button>测试http请求</el-button>-->
<!--    <el-button @click="">测试boss的登录接口并且管理cookie</el-button>-->
<!--    <el-button @click="testAxios">测试一下axios</el-button>-->
<!--    <el-button @click="bossLogin">刷新</el-button>-->
<!--    <el-button @click="simulatedDelivery">模拟海投程序</el-button>-->
<!--    <el-button @click="commit">测试进程间通信</el-button>-->
<!--    <el-button @click="selectCard">单独执行卡片地区匹配</el-button>-->
<!--    <el-button @click="testRouter">测试路由跳转</el-button>-->
<!--    <el-button @click="SQLTest">SQLite存储测试</el-button>-->
<!--    <el-button @click="SQLSelect">SQLite数据查询命令</el-button>-->

    <!-- 显示查询结果 -->
    <el-table :data="dbRows" style="width: 100%" border :resizable="true">
      <el-table-column prop="user_phone" label="用户手机号" show-overflow-tooltip></el-table-column>
      <el-table-column prop="job_title" label="工作标题" show-overflow-tooltip></el-table-column>
      <el-table-column prop="job_detail" label="工作详情(合适的话才有)" show-overflow-tooltip></el-table-column>
      <el-table-column prop="job_match" label="是否符合条件" show-overflow-tooltip></el-table-column>
      <el-table-column prop="additional_greet" label="问候语" show-overflow-tooltip></el-table-column>
      <el-table-column prop="into_time" label="匹配时间" show-overflow-tooltip></el-table-column>
      <el-table-column prop="user_inclination" label="用户期望工作" show-overflow-tooltip></el-table-column>
      <el-table-column prop="city" label="城市" show-overflow-tooltip></el-table-column>
      <el-table-column prop="user_job_expect" label="用户简述需求" show-overflow-tooltip></el-table-column>
      <el-table-column label="操作" fixed="right" header-align="center" align="center" width="150">
        <template #default="scope">
          <el-button type="primary" link >打招呼</el-button>
          <el-button type="primary" link>删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
        background
        layout="prev, pager, next, total"
        :total="totalItems"
        :page-size="pageSize"
        :current-page="currentPage"
        @current-change="handlePageChange">
    </el-pagination>
  </div>
</template>

<script setup lang="ts">
import axios from "axios";
import {onMounted, ref, watch} from "vue";
import router from "../router";

// 二维码信息
const qrCodeValue = ref('');

// 监听qrCodeValue的变化
watch(qrCodeValue, async (newValue, oldValue) => {
  if (newValue !== '' && oldValue === '') {
    // 如果二维码的值由空变为非空，发送请求
    await sendScanRequest(newValue);
  }
});

// 测试路由跳转
const testRouter = async () => {
  router.push('/submitResume')
}

// 分页状态
const dbRows = ref([]);
const currentPage = ref(1);
const pageSize = ref(10);
const totalItems = ref(0);

// 定义一个函数来发送请求
const testAxios = async () => {
  try {
    const res = await axios.get("https://www.zhipin.com/");
    console.log("打印响应信息:", res.data);
  } catch (error) {
    console.error("请求出错:", error);
  }
};

// 发送扫描请求
const sendScanRequest = async (qrId: string) => {
  try {
    const res = await axios.get(`https://www.zhipin.com/wapi/zppassport/qrcode/scanLogin?qrId=${qrId}`);
    console.log("扫码登录响应:", res.data);
    // 这里可以处理扫码登录成功后的逻辑
  } catch (error) {
    console.error("扫码登录请求出错:", error);
  }
};

// 测试boss直聘的登录接口 并且管理cookie
const bossLogin = async () => {
  try {
    const res = await axios.post("https://www.zhipin.com/wapi/zppassport/captcha/randkey");
    console.log("打印响应信息:", res.data);
    qrCodeValue.value = res.data.zpData.qrId;
    console.log("打印这个二维码值:", qrCodeValue.value);
  } catch (error) {
    console.error("请求出错:", error);
  }
}


//详情
const bossDetail = async () => {
  try {
    const res = await axios.get("https://www.zhipin.com/wapi/zpgeek/pc/recommend/job/list.json?city=101230200&experience=&payType=&partTime=&degree=&industry=&scale=&salary=&jobType=&encryptExpectId=&mixExpectType=&page=2&pageSize=15");
    console.log("打印响应信息:", res.data);
  } catch (error) {
    console.error("请求出错:", error);
  }
}


const communication = async () => {
  try {
    // const res = await service.get("?bossId=0563b42668224e2a33B73di9GVs~&bossSource=0&securityId=0v4379RoOOuGr-g1bmLmYjKPKIz1V8L4UNlfxvL0LVVz5THxQ4qROZXIoZpbBDgZaRBMUnGYey6NEbdrzjLLUPJZR5b8KUBIOiXxJxRW0x8cKzg5injiKOJtUyM6MKpuNhgr7S2afI1MhQ1R09L8-C2k4ovjdHdfkDRvSfYwz6IddYHPBJrvPE4TY-dHp9S2_4D2BhwNWQDDue1iy46KVcT6Sf7AR9vFY0Kfi96f6zjVFCt8rpDu-ujsxuPUP_0fIvq5GvBaYWQi84a9ppxGEuYTFGozkodspcuRkEhBA09wHcmXvcuksqzkwNCrL33RVIhFqeQSyywPy9Giev3oxvo_GT3kjkZ5opWmdGDofm9R_hn84w_9QLnqpc7gxMPeLuy3HUE7b9aQSYm6Vscpm53_VgSFKlYKo27b3CELKirK1_Wj2t4w5gWP9466Lme8i-itN8o8VI1GeaegoHnjPI9U-kUEStAbHJC8cCO-VSVkVFkWECzCFG4uLM4oqJG9qXLJlWqnj4BuXHH83_5a2Fy--BmW");

    // console.log("打印响应信息:", res.data);
  } catch (error) {
    console.error("请求出错:", error);
  }
}
// 捕获站点cookie
const getMainWindowCookie = async () => {
      console.log("===============")
      // 调用 bossHandleApi 获取 cookies
      const cookies = await window.bossHandleApi.getCookies();
      console.log('打印获取到的 cookies:', cookies);
      let zpToken = '';
      cookies.forEach(cookie => {
        if (cookie.name === 'geek_zp_token') {
          zpToken = cookie.value;
        }
      });

      console.log('zp_token:', zpToken);
//   获取动态Token
  const timestamp = Date.now();
  axios.get('https://www.zhipin.com/wapi/zppassport/get/zpToken?v2='+timestamp,
      {
        headers:{
          'zp_token': zpToken,
          'token':'3GXWkRL8yhsInHQ9',
        }
      })
      .then(res => {
        console.log('获得动态token',res)
      })
}



//测试渲染进程和主进程的沟通
const commit = async ()=>{
  const res = await window.bossHandleApi.testCommit()
  console.log(res)
}

//模拟海投程序
const simulatedDelivery = async ()=>{

  const condition ='{\n' +
      '  "city": "厦门/集美",\n' +
      '  "jobType": "全职",\n' +
      '  "salary": "不限",\n' +
      '  "jobYear": "不限",\n' +
      '  "educational": "不限",\n' +
      '  "industry": "云计算",\n' +
      '  "companyScale": "不限",\n' +
      '  "likeJob": "软件测试（厦门）",\n' +
      '  "analysisDetail": "",\n' +
      '  "jobKeywords": ["软件测试","JAVA开发"],\n' +
      '  "userJobExpect": "我想找一个JAVA开发或者测试开发的岗位，然后月薪的话三千以上就行，我会的技术主要有微服务，有几段大厂实习经历，请帮我进行简历投递"\n' +
      '}'
  console.log('=========xuan ran ===========')
  await window.bossSendApi.simulatedDelivery(condition)
}

const selectCard = async ()=>{
  const condition ='{\n' +
      '  "city": "厦门/集美",\n' +
      '  "jobType": "全职",\n' +
      '  "salary": "不限",\n' +
      '  "jobYear": "不限",\n' +
      '  "educational": "不限",\n' +
      '  "industry": "云计算",\n' +
      '  "companyScale": "不限",\n' +
      '  "likeJob": "软件测试（厦门）",\n' +
      '  "analysisDetail": "",\n' +
      '  "jobKeywords": ["软件测试","JAVA开发"],\n' +
      '  "userJobExpect": "我想找一个JAVA开发或者测试开发的岗位，然后月薪的话三千以上就行，我会的技术主要有微服务，有几段大厂实习经历，请帮我进行简历投递"\n' +
      '}'
  console.log('=========xuan ran ===========')
  await window.bossSendApi.selectCardCondition(condition)
}


const SQLTest = async () => {
  try {
    // const result = await window.bossHandleApi.dbSelect()
    const data = {
      user_phone: '13030835706', // 替换为实际的电话号码
      job_title: 'JAVA开发工程师', // 替换为实际的工作标题
      job_detail: '工作详情', // 替换为实际的工作详情
      job_match: 'true', // 替换为实际的匹配信息
      additional_greet: '在吗', // 替换为实际的额外问候
      into_time: new Date().toISOString(), // 使用当前时间作为插入时间
      use_inclination: 'JAVA开发，软件测试', // 替换为实际的倾向性
    };
    const result = await window.bossHandleApi.dbInsert(data)
    console.log('result: ', result);
    // const db = await operateDb();
    // const result = await db.select('SELECT * FROM job_logs', []);

  } catch (error) {
    console.error('查询时出现错误:', error);
  }
};

const SQLSelect = async ()=>{
    const data = {
      id:'',//顺序
      user_phone: '', // 替换为实际的电话号码
      user_inclination: '', // 替换为实际的倾向性  倾向的工作
      user_job_expect:'',// 用户的介绍 人工智能部分
      is_delivery:'',//是否投递 0不投递 1投递
      job_title: '', // 替换为实际的工作标题
      job_detail: '', // 替换为实际的工作详情
      job_match: '', // 替换为实际的匹配信息
      additional_greet: '', // 替换为实际的额外问候
      into_time: '', // 使用当前时间作为插入时间
      city:"",
      page:'',
      limit:'',
      order: 'id',
      asc: true
    };
  const result = await window.bossHandleApi.dbSelect(data);
  dbRows.value = result
  // totalItems.value = result.total;  // 假设API返回结果包含total字段
  console.log('结果数据  result data：',result)
}
// 处理分页变化
const handlePageChange = async (page) => {
  currentPage.value = page;
  await SQLSelect();
};
onMounted(async ()=>{
  await SQLSelect();
})
</script>


<style scoped>
.cartoon-form-container{
  width: 1000px;
  height: 500px;
}
</style>
